
function CreateProgram(gl: any, vsSource: string, fsSource: string) {
    //创建程序对象
    const program = gl.createProgram();
    //创建着色对象
    const vShader = loadShader(gl, gl.VERTEX_SHADER, vsSource);
    const fShader = loadShader(gl, gl.FRAGMENT_SHADER, fsSource);
    //顶点着色器装进程序对象
    gl.attachShader(program, vShader);
    //片元着色器装进程序对象
    gl.attachShader(program, fShader);
    //webgl上下文对象和程序对象
    gl.linkProgram(program);
    return program;
}
//初始化着色器
function initShaders(gl: any, vsSource: string, fsSource: string) {
    //创建程序对象
    const program = gl.createProgram();
    //创建着色对象
    const vShader = loadShader(gl, gl.VERTEX_SHADER, vsSource);
    const fShader = loadShader(gl, gl.FRAGMENT_SHADER, fsSource);
    //顶点着色器装进程序对象
    gl.attachShader(program, vShader);
    //片元着色器装进程序对象
    gl.attachShader(program, fShader);
    //webgl上下文对象和程序对象
    gl.linkProgram(program);
    //启动程序对象
    gl.useProgram(program);
    //把程序对象挂到上下文对象上
    gl.program = program;
    return true;
}
//加载Shader(画笔,着色器类型,着色器文本)
function loadShader(gl: any, type: string, source: string) {
    const shader = gl.createShader(type);
    gl.shaderSource(shader, source);
    gl.compileShader(shader);
    return shader;
}


//Image统一加载
// Promise.all([
//     imgPromise(image),
// ]).then(() => {

// });
function imgPromise(img: HTMLImageElement) {
    return new Promise((resolve) => {
        img.onload = function () {
            resolve(img);
        }
    });
}

export {
    CreateProgram,
    initShaders,
    imgPromise,
}